<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>医疗安全事件上报表</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
</head>
<body>
<form class="layui-form" lay-filter="FormLoad">
    <table border="1px" width="100%" cellpadding="0">
        <tr >
            <td colspan="6" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医疗安全不良事件报告表</span> </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    报告时间：
                </td>
                <td colspan="2">
                    <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input">
                </td>

                <td>
                    报告人：
                </td>

                <td colspan="2">
                    <input type="text" name="reporter" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">

                <td colspan="1">
                    科室名称：
                </td>

                <td colspan="1">
                    <input type="text" name="reporter_department" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    床号
                </td>
                <td colspan="1">
                    <input type="text" name="patient_bed_num" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    住院号
                </td>
                <td colspan="1">
                    <input type="text" name="patient_num" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">

                <td>
                    姓名：
                </td>

                <td colspan="1">
                    <input type="text" name="patient_name" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    性别
                </td>
                <td colspan="1">
                    <select name="patient_sex" lay-verify="required">
                        <option value=""></option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </td>
                <td colspan="1">
                    年龄
                </td>
                <td colspan="1">
                    <input type="text" name="patient_age" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">

                <td>
                    主管医生：
                </td>

                <td colspan="2">
                    <input type="text" name="patient_main_doctor" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    主要当事人
                </td>
                <td colspan="2">
                    <input type="text" name="patient_main_witness" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">

                <td>
                    入院时间：
                </td>

                <td colspan="2">
                    <input type="text" name="patient_hospitalized_time" id="patient_hospitalized_time" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    手术时间：
                </td>
                <td colspan="2">
                    <input type="text" name="patient_operation_time" id="patient_operation_time" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <td colspan="6" style="text-align: center; height: 30px"> <span style=" font-size: 12px">诊断</span> </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="2">
                    简要诊疗经过及不良事件描述：
                </td>

                <td colspan="4">
                    <textarea name="treatment_describe" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="2">
                    患者目前状况：
                </td>
                <td colspan="4">
                    <textarea name="patient_now_situation" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>
<!--        <tr>        <td colspan="6" style="text-align: center; height: 30px"> <span style=" font-size: 12px">以上内容由科室填写</span> </td>        </tr>-->
<!--        <tr>-->
<!--            <div class="layui-form-item">-->
<!--                <td colspan="2">-->
<!--                    收到报告时间：-->
<!--                </td>-->
<!--                <td colspan="4">-->
<!--                    <input type="text" name="department_know_time" id="department_know_time" placeholder="" class="layui-input">-->
<!--                </td>-->
<!--            </div>-->
<!--        </tr>-->
<!--        <tr>-->
<!--            <div class="layui-form-item">-->
<!--                <td colspan="2">-->
<!--                    处理情况简述：-->
<!--                </td>-->
<!--                <td colspan="4">-->
<!--                    <textarea name="department_deal" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>-->
<!--                </td>-->
<!--            </div>-->
<!--        </tr>-->
<!--        <tr>        <td colspan="6" style="text-align: center; height: 30px"> <span style=" font-size: 12px">以上内容由医务科填写</span> </td>        </tr>-->
        <tr>        <td colspan="6">
            <span>附表：医疗不良事件</span>
            <ol>
                <li>1.病症诊疗问题：。。。。。。。。。。。</li>
                <li>2.意外事件：包括。。。。。。。。。。。。</li>
                <li>3.辅助治疗：包括。。。。。。。。。。。。</li>
                <li>4.手术相关问题：包括。。。。。。。。。。。。</li>
                <li>5.医务沟通：包括。。。。。。。。。。。。</li>
                <li>6.其他导致不良后果：包括。。。。。。。。。。。。</li>
            </ol>
        </td>       </tr>

    </table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center; margin-top: 50px">
            <button class="layui-btn" lay-submit lay-filter="YiLiaoqx">立即提交</button>
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script>

    layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
        let $ = layui.jquery;
        let form = layui.form;
        let laydate = layui.laydate;
        var layer = layui.layer;
        var router = layui.router();
        laydate.render({
            elem: '#report_date' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#patient_hospitalized_time' //指定元素
            , type: 'date'
        })
        laydate.render({
            elem: '#patient_operation_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#department_know_time' //指定元素
            , type: 'date'
        });


        form.render();
        // 获取地址的中的值
        let user_code=decodeURIComponent(router.search.user_code);
        let user_name=decodeURIComponent(router.search.user_name);
        let dept_code=decodeURIComponent(router.search.dept_code);
        let dept_name=decodeURIComponent(router.search.dept_name);
        // layui data 保存数据
        if( user_code=="undefined"){
            console.log(layui.data('user').userinfo.user_name)
        } else{
            console.log(user_code);
            console.log("地址有值")
            layui.data('user', {
                key: 'userinfo',
                value:
                    {
                        user_name: user_name,
                        user_code: user_code,
                        dept_code:dept_code,
                        dept_name:dept_name
                    }
            });
            console.log(layui.data('user').userinfo.user_name)
        }
        //渲染 上报人和上报人单位
        form.val("FormLoad",{
            "reporter": layui.data('user').userinfo.user_name.replace(/\"/g, "") ,
            "reporter_department":layui.data('user').userinfo.dept_name.replace(/\"/g, "")
        })

        // submit 提交事件监听
        form.on('submit(YiLiaoqx)', function(data) {

            layer.confirm('确定提交吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '/event/event_insert',
                    type: "POST",
                    data:{
                        "reporter_code":layui.data('user').userinfo.user_code,
                        "reporter_name":layui.data('user').userinfo.user_name,
                        "dept_code":layui.data('user').userinfo.dept_code,
                        "dept_name":layui.data('user').userinfo.dept_name,
                        "event_code":11,
                        "report_date":data.field.report_date,
                        "reporter":data.field.reporter,
                        "reporter_department":data.field.reporter_department,
                        "patient_bed_num":data.field.patient_bed_num,
                        "patient_num":data.field.patient_num,
                        "patient_name":data.field.patient_name,
                        "patient_sex":data.field.patient_sex,
                        "patient_age":data.field.patient_age,
                        "patient_main_doctor":data.field.patient_main_doctor,
                        "patient_main_witness":data.field.patient_main_witness,
                        "patient_hospitalized_time":data.field.patient_hospitalized_time,
                        "patient_operation_time":data.field.patient_operation_time,
                        "treatment_describe":data.field.treatment_describe,
                        "patient_now_situation":data.field.patient_now_situation,
                        "department_know_time":data.field.department_know_time,
                        "department_deal":data.field.department_deal,
                        "status":2 //递交
                    },
                    success:function () {
                        layer.msg("保存成功");
                        form.val("FormLoad",{
                            "report_date":null,
                            "reporter":null,
                            "reporter_department":null,
                            "patient_bed_num":null,
                            "patient_num":null,
                            "patient_name":null,
                            "patient_sex":null,
                            "patient_age":null,
                            "patient_main_doctor":null,
                            "patient_main_witness":null,
                            "patient_hospitalized_time":null,
                            "patient_operation_time":null,
                            "treatment_describe":null,
                            "patient_now_situation":null,
                            "department_know_time":null,
                            "department_deal":null,
                        })
                        form.render();
                    },
                })

            }, function () {
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //save 保存事件监听
        form.on('submit(save)', function(data) {
            $.ajax({
                url: '/event/event_insert',
                type: "POST",
                data:{
                    "reporter_code":layui.data('user').userinfo.user_code,
                    "reporter_name":layui.data('user').userinfo.user_name,
                    "dept_code":layui.data('user').userinfo.dept_code,
                    "dept_name":layui.data('user').userinfo.dept_name,
                    "event_code":11,
                    "report_date":data.field.report_date,
                    "reporter":data.field.reporter,
                    "reporter_department":data.field.reporter_department,
                    "patient_bed_num":data.field.patient_bed_num,
                    "patient_num":data.field.patient_num,
                    "patient_name":data.field.patient_name,
                    "patient_sex":data.field.patient_sex,
                    "patient_age":data.field.patient_age,
                    "patient_main_doctor":data.field.patient_main_doctor,
                    "patient_main_witness":data.field.patient_main_witness,
                    "patient_hospitalized_time":data.field.patient_hospitalized_time,
                    "patient_operation_time":data.field.patient_operation_time,
                    "treatment_describe":data.field.treatment_describe,
                    "patient_now_situation":data.field.patient_now_situation,
                    "department_know_time":data.field.department_know_time,
                    "department_deal":data.field.department_deal,
                    "status": 1//1表示保存，可修改
                },
                success:function () {
                    layer.msg("保存成功");
                    form.val("FormLoad",{
                        "report_date":null,
                        "reporter":null,
                        "reporter_department":null,
                        "patient_bed_num":null,
                        "patient_num":null,
                        "patient_name":null,
                        "patient_sex":null,
                        "patient_age":null,
                        "patient_main_doctor":null,
                        "patient_main_witness":null,
                        "patient_hospitalized_time":null,
                        "patient_operation_time":null,
                        "treatment_describe":null,
                        "patient_now_situation":null,
                        "department_know_time":null,
                        "department_deal":null,
                    })
                    form.render();
                },
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>

</html>